package com.test.utils;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import static com.test.base.InitAppium.driver;

/**
 * Author:xuedonglei
 * Date: 2017/5/5
 */
public class GetScreenShot {

    /**
     * 截图
     *
     * @return
     */
    public static String getScreen() {
        String fileRoute = "路径";
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmm");
        String picname = fileRoute + df.format(new Date()).toString() + ".png";
        File screen = driver.getScreenshotAs(OutputType.FILE);
        System.out.println(picname);
        File screenFile = new File(picname);
        try {
            FileUtils.copyFile(screen, screenFile);
            String time = df.format(new Date()).toString();
            System.out.println("当前时间" + time);
            return time;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }


    /**
     * 截图 文件名: 内容-年月日时分秒
     */
    public static String getScreen(String name) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");

        // String picname = finalElement.phoneScreens + name + df.format(new Date()).toString() + ".png";
        String picname = "";

        File screen = driver.getScreenshotAs(OutputType.FILE);
        System.out.println(picname);
        File screenFile = new File(picname);
        try {
            FileUtils.copyFile(screen, screenFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return picname;
    }
}

